home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / 3D_Rendering / Musgrave_Shaders / Source / venus.sl < prev    next >
Encoding:
Text File  |  1994-12-08  |  3.0 KB  |  101 lines

  1. /*
  2.  * venus.sl - surface for a very cloudy planet like Venus.
  3.  *
  4.  *
  5.  * DESCRIPTION:
  6.  *      When put on a sphere, sets the color to look like a densely
  7.  *   clouded planet, very much like the real Venus appears in UV.
  8.  *      The shader works by creating a fractal turbulence function over
  9.  *   the surface to simulate the clouds.  Strong Coriolis forces are
  10.  *   simulated to give the twisting of clouds that is typically seen
  11.  *   on Venus.
  12.  *
  13.  *
  14.  * PARAMETERS:
  15.  *    Ka, Kd - the usual meaning
  16.  *    offset, scale - control the linear scaling of the cloud value.
  17.  *    twist - controls the twisting of the clouds due to Coriolis forces.
  18.  *    omega - controls the fractal characteristics of the clouds
  19.  *    octaves - the number of octaves of noise to sum for the clouds.
  20.  *
  21.  *
  22.  * HINTS:
  23.  *    The default values for the shader assume that the planet is
  24.  *    represented by a unit sphere.  The texture space and/or parameters
  25.  *    to this shader will need to be altered if the size of your planet
  26.  *    is radically different.
  27.  *
  28.  *
  29.  * AUTHOR: Ken Musgrave.
  30.  *    Conversion to Shading Language and minor modifications by Larry Gritz.
  31.  *
  32.  *
  33.  * REFERENCES:
  34.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  35.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  36.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  37.  *
  38.  *
  39.  * HISTORY:
  40.  *    ???? - Venus texture developed by F. Ken Musgrave.
  41.  *    Feb 1994 - Conversion to Shading Language by L. Gritz
  42.  *
  43.  * last modified 1 March 1994 by lg
  44.  */
  45.  
  46.  
  47.  
  48. #define TWOPI (2*PI)
  49.  
  50.  
  51. /* Use signed noise on [-1,1] */
  52. #define snoise(x) ((2*noise(x))-1)
  53.  
  54.  
  55.  
  56. surface
  57. venus (float Ka = 1, Kd = 1;
  58.        float offset = 1;
  59.        float scale = 0.6;
  60.        float twist = 0.22;
  61.        float omega = 0.65;
  62.        float octaves = 8;)
  63. {
  64.   point Ptexture;           /* the shade point in texture space */
  65.   point PtN;                /* normalized version of Ptexture */
  66.   point PP;                 /* Point after rotation by coriolis twist */
  67.   float rsq;                /* Used in calculation of twist */
  68.   float angle;              /* Twist angle */
  69.   float sine, cosine;       /* sin and cos of angle */
  70.   float l, o, a, i;         /* Loop control for fractal sum */
  71.   float value;              /* Fractal sum is stored here */
  72.  
  73.   /* Transform to texture coordinates */
  74.   Ptexture = transform ("shader", P);
  75.  
  76.   /* Calculate Coriolis twist, yielding point PP */
  77.   PtN = normalize (Ptexture);
  78.   rsq = xcomp(PtN)*xcomp(PtN) + ycomp(PtN)*ycomp(PtN);
  79.   angle = twist * TWOPI * rsq;
  80.   sine = sin (angle);
  81.   cosine = cos (angle);
  82.   PP = point (xcomp(Ptexture)*cosine - ycomp(Ptexture)*sine,
  83.           xcomp(Ptexture)*sine + ycomp(Ptexture)*cosine,
  84.           zcomp(Ptexture));
  85.  
  86.   /* Compute VLfBm */
  87.   l = 1;  o = 1;  a = 0;
  88.   for (i = 0;  i < octaves;  i += 1) {
  89.       a += o * snoise (PP * l);
  90.       l *= 2;
  91.       o *= omega;
  92.     }
  93.  
  94.   value = abs (offset + scale * a);
  95.  
  96.   /* Shade like matte, but with color scaled by cloud color */
  97.   Oi = 1;
  98.   Ci = Os * (value * Cs) * (Ka * ambient() +
  99.                 Kd * diffuse(faceforward(normalize(N),I)));
  100. }
  101.